package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.pojo.Clazz;
import com.example.zhxy.service.ClazzService;
import com.example.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * CJ
 */
@Slf4j
@Api(tags = "班级控制器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @ApiOperation("分页")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result Page(@PathVariable Integer pageNo,@PathVariable Integer pageSize,Clazz clazz){
        log.info(clazz.toString());
        Page<Clazz> page=new Page<>(pageNo,pageSize);
        IPage<Clazz> page1=clazzService.Ipage(page,clazz);
        return Result.ok(page1);
    }
    @ApiOperation("修改更新")
    @PostMapping("/saveOrUpdateClazz")
    public Result save(@RequestBody Clazz clazz){
        boolean b = clazzService.saveOrUpdate(clazz);
        if(b){
            return Result.ok();
        }else {
            return Result.fail().message("新增或修改失败");
        }
    }
    @ApiOperation("删除")
    @DeleteMapping("deleteClazz")
    public Result deleteClazz(@RequestBody List<Integer> list){
        boolean b = clazzService.removeByIds(list);
        if(b){
            return Result.ok();
        }else {
            return Result.fail().message("删除失败");
        }
    }
    @ApiOperation("查询班级")
    @GetMapping("/getClazzs")
    public Result getClazzs(){
        return Result.ok(clazzService.list(null));

    }
}
